#include "t_result.h"
#include <QGlobalStatic>
#include <QVBoxLayout>
#include <QMenu>
#include "ElaPlainTextEdit.h"
#include "savelog.h"

Q_GLOBAL_STATIC(T_Result,s_instance)

T_Result::T_Result(QWidget *parent)
{
    initUi();
}

T_Result::~T_Result()
{
    SaveLogIns->Stop();
}

T_Result *T_Result::Instance()
{
    return s_instance;
}

void T_Result::ClearText()
{
    m_plainTextEdit->clear();
}

void T_Result::initUi()
{
    setFixedSize(530,250);

    QWidget* centralWidget = new QWidget(this);
    centralWidget->setWindowTitle("过程结果");

    m_plainTextEdit = new ElaPlainTextEdit(this);
    m_plainTextEdit->setReadOnly(true);

    QVBoxLayout* centerLayout = new QVBoxLayout(centralWidget);
    centerLayout->addWidget(m_plainTextEdit);
    centerLayout->setContentsMargins(0, 0, 0, 0);
    addCentralWidget(centralWidget, true, true, 0);

    //启用日志
    //设置是否开启日志上下文打印，比如行号、函数等
    SaveLogIns->SetUseContext(false);
    //设置文件存储目录
    SaveLogIns->SetPath("/");
    SaveLogIns->SetMaxSize(1024*1024*1024);
    SaveLogIns->SetMaxRow(10000);
    connect(SaveLogIns,&SaveLog::flushLogUI,this,[=](const QString &msg){
        m_plainTextEdit->appendHtml(msg);
    });

    SaveLogIns->Start();
}
